package com.leesche.zcsp.node.web.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.leesche.zcsp.node.web.constants.Constants;
import com.leesche.zcsp.node.web.dao.SysNoticeDao;
import com.leesche.zcsp.node.web.model.SysNotice;
import com.leesche.zcsp.node.web.model.SysNoticeCriteria;
import com.leesche.zcsp.node.web.service.SysNoticeService;
import com.leesche.zcsp.node.web.service.impl.data.read.QuerySysNoticeCondition;
import com.leesche.zcsp.node.web.service.impl.data.read.SysNoticeDto;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author dennies yang
 * @version V1.0
 * @Title: SysNoticeServiceImpl.java
 * @Package com.leesche.zcsp.node.service.impl
 * @Description:()
 * @date 2016年9月22日 下午4:29:29
 */
@Service
@Transactional
public class SysNoticeServiceImpl
        extends BaseServiceImpl<SysNotice, SysNoticeCriteria, SysNoticeDto, QuerySysNoticeCondition, Long>
        implements SysNoticeService {
    @Autowired
    private SysNoticeDao sysNoticeDao;

    @Autowired
    public void setBaseDao(SysNoticeDao sysNoticeDao) {
        super.setBaseDao(sysNoticeDao);
    }

    /*
     * (non-Javadoc)
     *
     * @see
     * com.leesche.zcsp.node.web.service.SysNoticeService#findSysNotice(java.
     * lang.Integer)
     */
    @Override
    public SysNoticeDto findSysNotice(Integer userId) {
        // TODO Auto-generated method stub
        return sysNoticeDao.selectByUserID(userId);
    }

    /*
     * (non-Javadoc)
     *
     * @see
     * com.leesche.zcsp.node.web.service.SysNoticeService#getDefaultSysNotice()
     */
    @Override
    public SysNoticeDto getDefaultSysNotice() {
        // TODO Auto-generated method stub
        return new SysNoticeDto(Constants.NOTICE_DEFAULT_LOGOURL, Constants.NOTIC_DEFAULT_COMPANYNAME,
                Constants.NOTIC_DEFAULT_BUTTOMCONTENT);
    }

    @Override
    public List<SysNoticeDto> findListsByCondition(QuerySysNoticeCondition condition) {
        return sysNoticeDao.selectListsByCondition(condition);
    }

    @Override
    public int addOrUpdateNotice(SysNotice notice) {
        if (findSysNotice(Integer.parseInt(notice.getUserid().toString())) != null) {
            SysNoticeCriteria criteria = new SysNoticeCriteria();
            criteria.or().andUseridEqualTo(notice.getUserid());
            //修改底部文字
            return updateByCriteriaSelective(notice, criteria);
        } else {
            // 增加底部文字
            return insertSelective(notice);
        }
    }
}
